package com.ruoyi.zsyh.controller;

import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAfterProduct;
import com.ruoyi.zsyh.service.IZsyhAfterProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后产品信息Controller
 * 
 * @author yuexl
 * @date 2022-08-22
 */
@Controller
@RequestMapping("/zsyh/afterProduct")
public class ZsyhAfterProductController extends BaseController
{
    private String prefix = "zsyh/afterProduct";

    @Autowired
    private IZsyhAfterProductService zsyhAfterProductService;

    @RequiresPermissions("zsyh:afterProduct:view")
    @GetMapping()
    public String afterProduct()
    {
        return prefix + "/afterProduct";
    }

    @GetMapping("/productView")
    public String productView()
    {
        return prefix + "/productView";
    }

    /**
     * 查询售后产品信息列表
     */
    @RequiresPermissions("zsyh:afterProduct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhAfterProduct zsyhAfterProduct)
    {
        startPage();
        List<ZsyhAfterProduct> list = zsyhAfterProductService.selectZsyhAfterProductList(zsyhAfterProduct);
        return getDataTable(list);
    }

    /**
     * 查询售后产品信息列表
     */
    @RequiresPermissions("zsyh:afterProduct:list")
    @PostMapping("/listById")
    @ResponseBody
    public TableDataInfo listById(String id)
    {
        List<ZsyhAfterProduct> list = new ArrayList<ZsyhAfterProduct>();
        ZsyhAfterProduct zsyhAfterProduct = zsyhAfterProductService.selectZsyhAfterProductById(id);
        list.add(zsyhAfterProduct);
        return getDataTable(list);
    }

    /**
     * 导出售后产品信息列表
     */
    @RequiresPermissions("zsyh:afterProduct:export")
    @Log(title = "售后产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAfterProduct zsyhAfterProduct)
    {
        List<ZsyhAfterProduct> list = zsyhAfterProductService.selectZsyhAfterProductList(zsyhAfterProduct);
        ExcelUtil<ZsyhAfterProduct> util = new ExcelUtil<ZsyhAfterProduct>(ZsyhAfterProduct.class);
        return util.exportExcel(list, "售后产品信息数据");
    }

    /**
     * 新增售后产品信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售后产品信息
     */
    @RequiresPermissions("zsyh:afterProduct:add")
    @Log(title = "售后产品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAfterProduct zsyhAfterProduct)
    {
        return toAjax(zsyhAfterProductService.insertZsyhAfterProduct(zsyhAfterProduct));
    }

    /**
     * 修改售后产品信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterProduct zsyhAfterProduct = zsyhAfterProductService.selectZsyhAfterProductById(id);
        mmap.put("zsyhAfterProduct", zsyhAfterProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存售后产品信息
     */
    @RequiresPermissions("zsyh:afterProduct:edit")
    @Log(title = "售后产品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAfterProduct zsyhAfterProduct)
    {
        return toAjax(zsyhAfterProductService.updateZsyhAfterProduct(zsyhAfterProduct));
    }

    /**
     * 删除售后产品信息
     */
    @RequiresPermissions("zsyh:afterProduct:remove")
    @Log(title = "售后产品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhAfterProductService.deleteZsyhAfterProductByIds(ids));
    }
}
